package com.fourthGroup.controller;


import com.alibaba.fastjson2.JSON;
import com.fourthGroup.model.Product;
import com.fourthGroup.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping("/product/{pid}")
    public Product getProductById(@PathVariable("pid") Integer pid) {
        log.info("查询{}产品信息",pid);
        Product product = productService.queryProductById(pid);
        log.info("商品信息查询成功，内容为{}", JSON.toJSONString(product));
        return product;
    }

}
